<template>
  <div>
    <div class="incolumn_countr">
      <div class="search-box">
        <hy-search
          ref="query"
          :searchTitle="searchTitle"
          v-model="searcher"
          :button="{btnShowBy3:true}"
          :buttonText="{btnNameBy3:'新增文档'}"
          :col="6"
          @search="getlist(0)"
          @clickbybtn3="jump"
        ></hy-search>
      </div>
    </div>
    <div class="table-box">
      <template>
        <el-table
          :data="tableData"
          style="width: 100%;background-color:#fff"
          :cell-style="rowClass"
          :header-cell-style="headClass"
          :max-height="620"
          stripe
        >
          <el-table-column prop="xuhao" label="序号" align="center" width="100"></el-table-column>
          <el-table-column prop="createon" label="发布日期" align="center"></el-table-column>
          <el-table-column prop="name" label="文档名称" align="center"></el-table-column>
          <el-table-column prop="typea" label="文档类型" align="center"></el-table-column>
          <el-table-column prop="path" label="文档地址" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column prop="count" label="下载次数" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column prop="state" label="状态" align="center"></el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button size="small" type="warning" @click="bianji(scope.row.Id)">编辑</el-button>
              <el-button size="small" type="primary" @click="xiangq(scope.row.Id)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <template>
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
        :total="total"
        style="text-align：center"
      ></el-pagination>
    </template>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      empno: "",
      total: 1,
      current: 1,
      pagesize: 10,
      searchTitle: [
        {
          type: "input",
          name: "customProductName",
          label: "输入搜索",
          placeholder: "请输入文档名称",
          prop: "customProductName"
        },
        {
          type: "date2",
          name: "issuanceDate",
          label: "输入时间",
          placeholder: "请选择输入时间",
          prop: "issuanceDate"
        }
      ],
      searcher: {
        customProductName: "",
        customProductNo: "",
        issuanceDate: ""
      },
      tableData: []
    };
  },
  created () {
    this.empno = JSON.parse(localStorage.getItem('empno'))
    this.getlist(0)
  },
  methods: {
    // 分页
    handleCurrentChange (e) {
      this.getlist(e - 1);
    },
    // 表头样式设置
    headClass () {
      return "text-align:center;";
    },
    // 表格样式设置
    rowClass () {
      return "text-align: center;";
    },

    bianji (value) {
      var val = ""
      this.$router.push({ path: "./Documentdownloadsbianji", query: { val: value } });
    },
    xiangq (value) {
      var val = ""
      this.$router.push({ path: "./Documentdownloadsxiangq", query: { val: value } });
    },
    jump () {
      this.$router.push({ path: "/ADDocumentdownloads" });
    },
    getlist (page) {
      var obj =
      {
        pn: page,
        PerPageSize: 10,
        key: this.searcher.customProductName ? this.searcher.customProductName : '',
        start: this.searcher.issuanceDate[0] ? this.searcher.issuanceDate[0] : '',
        end: this.searcher.issuanceDate[1] ? this.searcher.issuanceDate[1] : '',
      }
        ;
      var objs = JSON.stringify(obj);
      axios(
        "/apis/AdministrativeManagement.asmx/Uploaddocument?index=1&jsondata=" + objs + "&empno=" + this.empno
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var stafflist = JSON.parse(datas.string.__text);
        for (var i = 0; i < stafflist.length; i++) {
          var dd = new Date(parseInt(stafflist[i].createon.substr(6, 13)));
          var y = dd.getFullYear();
          var m = dd.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          var d = dd.getDate();
          d = d < 10 ? "0" + d : d;
          stafflist[i].createon = y + "-" + m + "-" + d + " ";
        }
        this.tableData = stafflist
        for (var i = 0; i < stafflist.length; i++) {
          this.tableData[i].xuhao = 1 + i + 10 * page;
        }
        this.total = JSON.parse(datas.string.__text).total;
        console.log(stafflist)
      });
    },
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
@import '@/assets/scss/search.scss';
.container {
  background-color: $bgcolor;
}
.incolumn_countr {
  width: 97%;
}
.top-box {
  width: 100%;
  height: 100px;
  padding-left: 1%;
  padding-top: 10px;
  //   border: 1px solid $red;
  background-color: $white;
  margin-bottom: 20px;
}

.table-box {
  width: 98%;
  height: 620px;
  //  border: 1px solid $red;
  margin: 0 auto;
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.btn-box {
  width: 30%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
  float: right;
  margin-right: 2%;
}
.sea-box {
  width: 90%;
  float: left;
  // border: 1px solid red;
}
.hy_search {
  margin-top: 10px;
}
.sear-box {
  width: 8%;
  float: left;
  margin-left: 2%;
  //  border: 1px solid red;
}
.btn {
  float: right;
  margin-top: 10px;
}
</style>
